package smsBean;

import java.sql.ResultSet;
import java.util.Hashtable;

import utility.CharAt;
import utility.ConvertToLower;
import utility.Index;
import control.Command;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class DictionaryDetails 
{
	public Hashtable<Object,Object> tempDictionaryMap = new Hashtable<Object, Object>();
	String str;
	String message;
	String tableName;
	int cnt;
	String PropertyField;
	String process;
	String spChar=null;
	DBManager sqlDB ;
	ResultSet rs;
	GetIdName gin;
	
	public DictionaryDetails(int cnt,String msg,String tableName,DBManager sqlDB,String process )
	{
		message = msg;
		this.str= msg;
		this.cnt = cnt;
		this.tableName = tableName;
		this.process=process;		
		this.sqlDB= sqlDB;
		System.out.println("pool::DictionaryDetails::Message in property : "+str);
	}
	
	public DictionaryDetails(DBManager sqlDB)
	{
		this.sqlDB = sqlDB;
		gin = new GetIdName(this.sqlDB);
	}

	public Hashtable<Object, Object> DictionaryData() 
	{		
		int count=0;
		String spcharAdd = null;
		//String tempStr=str;
		int i=0;
		int start=0,end=0;
		String retStr;
		Command cd=new Command(tableName,sqlDB);
	
	
		spcharAdd = ""+CharAt.CharAT(message, 0);
		
		while(i<str.length())
		{
			char ch = CharAt.CharAT(str,i);			
			if(ch == spcharAdd.toCharArray()[0])
			{
				count ++;
				
				if (count == cnt)
				{		
					start = Index.indexOf(str, spcharAdd,i);
					end = Index.indexOf(str, spcharAdd,start+1);
					
					if (end == -1)
					{
						retStr = str.substring(start);
						//retStr = cd.getLastProperty(msg, tableName, process);						
					}
					else
						retStr = str.substring(start,end);
					
					System.out.println("String needed -->> " + retStr);
					tempDictionaryMap = ConvertToLower.convertHashKey(cd.getHashCommand(tableName, retStr,process));
					if(tempDictionaryMap.containsKey("ErrorInput"))
					{
						return tempDictionaryMap;
					}					
					
					return tempDictionaryMap;
				}
			}
			i++;
		}
		return tempDictionaryMap;		
	}
	
	
}